package com.maoxx.stuchoosemssbv_service.service;

import com.maoxx.stuchoosemssbv_service.entity.Student;
import com.maoxx.stuchoosemssbv_service.entity.Teacher;
import com.maoxx.stuchoosemssbv_service.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: TeacherService
 * @author: Maoxx
 * @date: 2024/11/2 20:31
 * @Version: 1.0
 * @description:
 */

@Service
public class TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    public Teacher findById(Integer tid) {
        return teacherMapper.findById(tid);
    }

    public List<Teacher> findAll() {
        return teacherMapper.findAll();
    }

    public boolean updateById(Teacher teacher) {
        return teacherMapper.updateById(teacher);
    }

    public List<Teacher> findByPage(Integer page, Integer size) {
        List<Teacher> studentList = teacherMapper.findAll();
        List<Teacher> list = new ArrayList<>();

        int start = size * page;
        int end = size * (page + 1);
        int sz = studentList.size();

        for (int i = start; i < end && i < sz; i++) {
            list.add(studentList.get(i));
        }

        return list;
    }

    public boolean save(Teacher teacher) {
        return teacherMapper.save(teacher);
    }

    public boolean removeById(Integer tid) {
        return teacherMapper.removeById(tid);
    }
}
